<template>
  <div class="header">
    <!-- 头部 -->
    <van-row class="bacc" style="position:fixed;z-index: 1;width: 100%;">
      <van-col span="4" style="overflow: hidden">
        <img
          class="icon"
          src="@/assets/icon.png"
          v-if="!$store.state.islogin"
        />
        <van-image
          v-else
          round
          width="40px"
          :src="$store.state.avatar"
          style="margin: 5px 0px 0px 10px;"
        />
      </van-col>
      <van-col span="15">
        <!-- 搜索框 -->
        <van-search
          class="bacc index_header_search"
          v-model="search"
          shape="round"
          placeholder="请输入搜索关键字"
          maxlength="50"
          @search="onSearch"
        >
        </van-search>
      </van-col>
      <!-- 搜索按钮 -->
      <van-button
        type="info"
        size="small"
        style="margin: 12px 0px 0px 17px;"
        @click="onSearch"
        >搜索</van-button
      >
    </van-row>
  </div>
</template>
<script>
export default {
  data() {
    return {
      search: "",
    };
  },
  methods: {
    onSearch() {
      this.$emit("chuanfuji", this.search);
    },
  },
  watch: {
    search() {
      if (this.search !== "") {
        this.$emit("chuanfuji", this.search);
      } else {
        // console.log(`搜索框为空`);
        this.$emit("chuanfuji", "");
      }
    },
  },
};
</script>
<style scoped>
.bacc {
  background-color: rgb(123, 183, 253);
}
.icon {
  width: 45px;
  display: inline-block;
  margin: 4px 0 0 13px;
}
.index_header_search {
  padding: 10px 0 10px 0;
  background-color: rgb(123, 183, 253);
}
</style>
